/***************************************************************************
 *
 * File name: q1.c
 *
 * Author:  Tomer Filiba
 *          03701307-5
 *          sebulba@t2
 *
 *
 * Exercise #: 2
 * Question #: 1
 *
 * Submission Date: 11/6
 *
 **************************************************************************/

/*-------------------------------------------------------------------------
  Include files:
--------------------------------------------------------------------------*/
#include <stdio.h>
#include <math.h>


/*=========================================================================
  Constants and definitions:
==========================================================================*/
#define GREAT_SUCCESS		(0)
#define I_WILL_BE_EXECUTE	(1)
#define MAX_LINE_SIZE		(250)
#define UPPER_MIN			('A')
#define UPPER_MAX			('Z')
#define LOWER_MIN			('a')
#define LOWER_MAX			('z')
#define DIGIT_MIN			('0')
#define DIGIT_MAX			('9')


/*-------------------------------------------------------------------------
  The main program: read a line from stdin and print details about each
  character the user has input
 -------------------------------------------------------------------------*/
int main1(int argc, const char ** argv)
{
	char buf[MAX_LINE_SIZE];
	char *ch, *kind;
	char c, last = 0;
	
	/* get input from user */
	printf("Enter text: ");
	if (fgets(buf, MAX_LINE_SIZE, stdin) == NULL) {
		printf("Error reading from stdin\n");
		return I_WILL_BE_EXECUTE;
	}
	printf("\n");
	
	/* display info about each character until \0 or \n */
	for (ch = buf, c = *ch; c != '\0' && c != '\n'; c = *ch++)
	{
		/* determine kind of character */
		if (c >=  UPPER_MIN && c <= UPPER_MAX)
			kind = "upper";
		else if (c >=  LOWER_MIN && c <= LOWER_MAX)
			kind = "lower";
		else if (c >=  DIGIT_MIN && c <= DIGIT_MAX)
			kind = "digit";
		else
			kind = "misc";
		
		/* print info line (each column is padded) */
		printf("%c", c);
		printf("%10d", c);
		printf("%10.2f", sqrt(c));
		printf("%10d", c*c);
		printf("%+10d", c - last);
		printf("     %s", kind);
		printf("\n");
		last = c;
	}
	
	return GREAT_SUCCESS;
}


/**************************************************************************
			                          End of file
***************************************************************************/